package com.wangzhen.spring.rabbit.producer;

import com.wangzhen.spring.rabbit.entity.Order;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.support.CorrelationData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class OrderProducer {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void sendOrder(Order order) throws Exception {
        rabbitTemplate.convertAndSend("order-exchange", //交换机名称
                "order.123",                           //路由key
                order,                                            //消息内容
                new CorrelationData(order.getMsgId())             //CorrelationData消息唯一ID
        );
    }
}
